package com.service.impl;

import com.bean.*;
import com.dao.PurchaseDao;
import com.dao.impl.PurchaseDaoImpl;
import com.service.PurchaseService;

import java.util.ArrayList;
import java.util.List;

public class PurchaseServiceImpl implements PurchaseService {
    private PurchaseDao purchaseDao = new PurchaseDaoImpl();

    public Purchase purchaseInit(User user,Supplier supplier){
        return purchaseDao.purchaseInit(user,supplier);
    };

    @Override
    public List<PurchaseInfo> getAllGoods(User user, Supplier supplier) {
        Purchase purchase = purchaseDao.purchaseInit(user,supplier);
        return purchaseDao.getAllGoods(purchase);
    }

    @Override
    public boolean addGoods(Goods goods, int number, Purchase purchase) {
        if (purchaseDao.addGoods(goods, number, purchase) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean deleteGoods(int key) {
        if (purchaseDao.deleteGoods(key) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean updateGoodsNumber(int key, int number) {
        if (purchaseDao.updateGoodsNumber(key,number) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean inWarehouse(User user, Supplier supplier) {
        Purchase purchase = new Purchase();
        purchase = purchaseDao.purchaseInit(user,supplier);
        List<PurchaseInfo> purchaseInfos = new ArrayList<>();
        purchaseInfos = purchaseDao.getAllGoods(purchase);
        if (purchaseDao.inWarehouse(purchaseInfos) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean haveNotInPurchaseExist(User user, Supplier supplier) {
        return purchaseDao.haveNotInPurchaseExist(user,supplier);
    }

    @Override
    public boolean isGoodsExist(Goods goods) {
        return purchaseDao.isGoodsExist(goods);
    }

    @Override
    public List<Purchase> getAllPurchase() {
        return purchaseDao.getAllPurchase();
    }

    @Override
    public Purchase getSelectPurchase(int key) {
        return purchaseDao.getSelectPurchase(key);
    }

    public List<PurchaseInfo> getSelectGoods(Purchase purchase){
       return purchaseDao.getAllGoods(purchase);
    };

    public List<Purchase> getFindPurchase(String supplier,String startDate,String endDate){
        return purchaseDao.getFindPurchase(supplier,startDate,endDate);
    };

}
